<?php

namespace App\Http\Controllers\Front;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

use App\Interfaces\DiscountService;
use App\Exception\Front\DiscountException;
use Auth;

class DiscountController extends Controller
{
    /**
     * 根据要购买的商品数组获取用户购买这些商品时可用的限时折扣
     *
     * @param array $buyGoods               商品数组,$buyGoods = ["483" => "2", "503" => "1"];
     * @param int $current_discount_arr     已经选中的要使用的限时折扣以及该折扣要使用的商品数量 current_discount_arr = ['discount_id' => 1, 'goods_number' => 2]
     * @return \Illuminate\Http\Response
     */
    public function getUserCanUseDiscount(Request $request, DiscountService $discountService)
    {
        $return = ['status'=>1, 'message'=>'', 'data'=>''];

        //商品数组,$buyGoods = ["483" => "2", "503" => "1"];
        if ($request->buyGoods) {

            $return['status'] = 0;

            $return['message'] = '商品数组不能为空';

            return $return;
        }else{

            $buyGoods = $request->buyGoods;
        }

        //已经选中的要使用的限时折扣以及该折扣要使用的商品数量(可为空) current_discount_arr = ['discount_id' => 1, 'goods_number' => 2]
        if ($request->current_discount_arr) {

            $current_discount_arr = $request->current_discount_arr;
        }else{

            $current_discount_arr = [];
        }

        $return['data'] = $discountService->getUserCanUseDiscount(Auth::user()->id, $buyGoods, $current_discount_arr);

        return $return;

    }//end func index()


}